package thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * @author CY
 * @date 2023/03/19 20:05
 **/
public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
//        CountDownLatch countDownLatch = new CountDownLatch(3);

//        Thread thread = new Thread(new Runnable() {
//            int count = 1;
//            @Override
//            public void run() {
//               while(Thread.currentThread().isAlive()) {
//                   try {
//                       Thread.sleep(1000);
//                       System.out.println("第"+(count++)+"名选手已经到达");
//                       countDownLatch.countDown();
//
//                   } catch (InterruptedException e) {
//                       throw new RuntimeException(e);
//                   }
//               }
//            }
//        });
//        thread.start();
//        countDownLatch.await();
//        System.out.println("比赛结束");


        //
        final ExecutorService executorService = Executors.newFixedThreadPool(5);
        Semaphore semaphore = new Semaphore(3);

        for (int i = 1; i < 10; i++) {
            Thread thread=new Thread(new Runnable() {

                @Override
                public void run() {
                    System.out.println("hello");
                }
            });
            semaphore.acquire();
            thread.start();


        }


    }


}
